#pragma once
#include <string>
#include <vector>
#include <unordered_map>

struct SubmoduleConfig {
    std::string name;
    std::string path;
    std::string url;
    std::string branch;
};

class SubmoduleRewriter {
public:
    SubmoduleRewriter(const std::string& git_path = "");
    
    bool loadGitmodules(const std::string& repo_path);
    bool rewriteToMirrors();
    bool applyChanges();
    
    void addMirrorMapping(const std::string& source, const std::string& target);
    void setGitPath(const std::string& git_path) { git_path_ = git_path; }
    
    const std::vector<SubmoduleConfig>& getSubmodules() const { return submodules_; }

private:
    std::string git_path_;
    std::vector<SubmoduleConfig> submodules_;
    std::unordered_map<std::string, std::string> mirror_map_;
    std::string repo_path_;
    
    bool parseGitmodulesFile(const std::string& file_path);
    bool writeGitmodulesFile(const std::string& file_path);
    void initDefaultMirrors();
    std::string rewriteUrl(const std::string& original_url);
};
